Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
The reftools npm package is a utility library designed for managing and manipulating JSON references within JavaScript objects. It provides tools for resolving, merging, and cloning JSON references, making it useful for handling complex JSON structures that include internal references.
resolve
This feature resolves JSON references within the document. It replaces references with the actual data they refer to, simplifying the structure for easier manipulation and access.
const reftools = require('reftools');
let doc = { a: { b: { $ref: '#/c' } }, c: { d: 'hello' } };
let resolved = reftools.resolve(doc);
console.log(resolved);
merge
This feature merges two JavaScript objects, incorporating properties from the source object into the destination object. It's particularly useful for combining configurations or settings.
const reftools = require('reftools');
let src = { a: 1 };
let dst = { b: 2 };
reftools.merge(src, dst);
console.log(dst);
clone
This feature creates a deep clone of an object, including resolving any internal JSON references. This is useful for creating independent copies of complex objects that include references.
const reftools = require('reftools');
let original = { a: { b: { $ref: '#/c' } }, c: { d: 'hello' } };
let cloned = reftools.clone(original);
console.log(cloned);
json-refs is a package that provides tools for resolving references in JSON objects. It is similar to reftools but focuses more on the resolution aspect and includes additional utilities for finding and listing unresolved references.
swagger-tools is a package primarily used for building and managing Swagger documents but includes functionality for resolving JSON references similar to reftools. It differs in that it is more specialized towards Swagger, whereas reftools is more general-purpose.
a no-op placeholder which returns the given object unchanged useful for when a clone function needs to be passed but cloning is not required
clones the given object using JSON.parse and JSON.stringify
clones the given object's properties shallowly, ignores properties from prototype
clones the given object's properties deeply, ignores properties from prototype
clones the given object's properties shallowly, using Object.assign
Source: stackoverflow http://bit.ly/2A1Kha6
dereferences the given object
flattens an object into an array of properties
escapes JSON Pointer using ~0 for ~ and ~1 for /
unescapes JSON Pointer using ~0 for ~ and ~1 for /
from obj, return the property with a JSON Pointer prop, optionally setting it to newValue
recurses through the properties of an object, given an optional starting state anything you pass in state.payload is passed to the callback each time
Simply modifies an object to have no self-references by replacing them with $ref pointers
Takes an object and creates a graph of JSON Pointer / References
Given an expanded object and an optional object to compare to (e.g. its $ref'd form), will call the following functions:
a no-op placeholder which returns the given object unchanged useful for when a clone function needs to be passed but cloning is not required
Kind: global function
Returns: the input object, unchanged
Param | Description |
---|---|
obj | the input object |
clones the given object using JSON.parse and JSON.stringify
Kind: global function
Returns: the cloned object
Param | Description |
---|---|
obj | the object to clone |
clones the given object's properties shallowly, ignores properties from prototype
Kind: global function
Returns: the cloned object
Param | Description |
---|---|
obj | the object to clone |
clones the given object's properties deeply, ignores properties from prototype
Kind: global function
Returns: the cloned object
Param | Description |
---|---|
obj | the object to clone |
clones the given object's properties shallowly, using Object.assign
Kind: global function
Returns: the cloned object
Param | Description |
---|---|
obj | the object to clone |
Source: stackoverflow http://bit.ly/2A1Kha6
dereferences the given object
Kind: global function
Returns: the dereferenced object
Definitions: a source of definitions to reference
Options: optional settings (used recursively)
Param | Description |
---|---|
o | the object to dereference |
flattens an object into an array of properties
Kind: global function
Returns: the flattened object as an array of properties
Param | Description |
---|---|
obj | the object to flatten |
callback | a function which can mutate or filter the entries (by returning null) |
escapes JSON Pointer using ~0 for ~ and ~1 for /
Kind: global function
Returns: the escaped string
Param | Description |
---|---|
s | the string to escape |
unescapes JSON Pointer using ~0 for ~ and ~1 for /
Kind: global function
Returns: the unescaped string
Param | Description |
---|---|
s | the string to unescape |
from obj, return the property with a JSON Pointer prop, optionally setting it to newValue
Kind: global function
Returns: the found property, or false
Param | Description |
---|---|
obj | the object to point into |
prop | the JSON Pointer or JSON Reference |
newValue | optional value to set the property to |
recurses through the properties of an object, given an optional starting state anything you pass in state.payload is passed to the callback each time
Kind: global function
Param | Description |
---|---|
object | the object to recurse through |
state | optional starting state, can be set to null or |
callback | the function which receives object,key,state on each property |
Simply modifies an object to have no self-references by replacing them with $ref pointers
Kind: global function
Returns: the re-referenced object (mutated)
Param | Description |
---|---|
obj | the object to re-reference |
options | may contain a prefix property for the generated refs |
Takes an object and creates a graph of JSON Pointer / References
Kind: global function
Returns: the graph suitable for passing to toposort()
Param | Description |
---|---|
obj | the object to convert |
containerName | the property containing definitions. Default: definitions |
Given an expanded object and an optional object to compare to (e.g. its $ref'd form), will call the following functions:
Kind: global function
Returns: the possibly mutated object
Param | Description |
---|---|
obj | the object to visit |
comparison | optional object to compare to |
callbacks | object containing functions as above |
Result
Try to get a topological sorting out of directed graph.
Kind: global typedef
Param | Type | Description |
---|---|---|
nodes | Object | A list of nodes, including edges (see below). |
Properties
Name | Type | Description |
---|---|---|
sort | array | the sort, empty if not found |
nodesWithEdges, | array | will be empty unless a cycle is found |
FAQs
Utility functions to deal with references in objects
The npm package reftools receives a total of 1,266,799 weekly downloads. As such, reftools popularity was classified as popular.
We found that reftools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.